class NetworkResource < ActiveRecord::Base
composed_of :cidr,
:class_name => 'NetAddr::CIDR',
:mapping => [ %w(network_address network), %w(cidr_range bits) ],
:allow_nil => true,
:constructor => Proc.new { |network_address, cidr_range| NetAddr::CIDR.create("#{network_address}/#{cidr_range}") },
:converter => Proc.new { |value| NetAddr::CIDR.create(value.is_a?(Array) ? value.join('/') : value) }
end
# This calls the :constructor
network_resource = NetworkResource.new(:network_address => '192.168.0.1', :cidr_range => 24)
# These assignments will both use the :converter
network_resource.cidr = [ '192.168.2.1', 8 ]
network_resource.cidr = '192.168.0.1/24'
# This assignment won't use the :converter as the value is already an instance of the value class
network_resource.cidr = NetAddr::CIDR.create('192.168.2.1/8')
# Saving and then reloading will use the :constructor on reload
network_resource.save
network_resource.reload
分享到:
相关推荐
snmp4j 1.8.2版 The org.snmp4j classes are capable of creating, ... A SNMP message is composed of its message header and its PDU payload. This package contains three main groups of classes and interfaces:
The eight voltage vectors U0 - U7 correspond to the possible ... Each of these states can be composed by a different equivalent electrical circuit. In Fig 2.19 the circuit for the vector U1 is presented.
This bas is composed of 35 Differant Gradient Color Fades. It is meant to inhance Interface Design without spending a lot of time on solely the interface.
在给定文件信息中,标题为“Molecular Gun Composed of Carbon Nanotube”,描述了胡知力和郭兴明使用分子动力学模拟,通过对双壁碳纳米管(DWCNT)一端的弯曲,能够以极高的速度弹射内层碳纳米管(CNT),这依赖于...
用含滞后势和超前势所构成的互能流来说明光的二重性,既是波又是光子,赵双任,杨开文,研究表明洛伦兹互易定理不适合一个含发射器和接收器的天线系统。正确的方法表明洛伦兹互易定理不适合一个含一个发射器和一个...
波达方向(Direction of Arrival, DOA)估计是无线通信、雷达系统、声学定位等领域中的关键技术,它涉及从多个方向到达的信号的检测和定位。在这些应用中,了解信号的DOA可以帮助我们更好地理解信号源的位置,提高...
Marlin是一个庞大的C++程序,由许多文件组成,其中最重要的文件包含了Marlin的所有编译时配置选项。在Marlin的源代码中,有三个关键文件用于管理这些配置: 1. **Configuration.h**:这个文件包含了核心的硬件设置...
is validated in hardware using a robotic motion simulator composed of a seven degrees-of-freedom (DOF) arm mounted on a six DOF base. The tradeoff between control requirements and fuel consumption is ...
Na30.5AgxGa60-x: A Three-Dimensional Network Composed of Ga3, Ga12, and Ga18 Clusters Na30.5AgxGa60�x: A Three-Dimensional Network Composed of Ga3, Ga12, and Ga18 Clusters Robert W. Henning and ...
(b) the name of the table, the names of the table's attributes, the data types of the table's attributes, the formats of the table's attributes, and the maximum number of rows that the table can have...
这个句子在描述群体的构成,"be composed of" 表示由...组成,符合上下文,所以选项B "is composed of" 是正确的。 8. "The yards are overgrown and cluttered with ___." 这里描述的是院子的状态,"trash" 指垃圾...
The lower (or local) map level is composed of a set of local maps that are guaranteed to be statistically inde- pendent. The upper (or global) level is an adjacency graph whose arcs are labeled with ...
7. 中国女子游泳冠军:提到"Some former Chinese women swimming champions c________ a song for the Olympics in Beijing",此处空白处可能是“composed”,即为中国女子游泳冠军为北京奥运会创作了一首歌。...
apply_rule_of_thirds('path_to_image.jpg', 'path_to_output.jpg') ``` ##### 2. 黄金比例构图 ```python def apply_golden_ratio(image_path, output_path): with Image.open(image_path) as img: draw = ...