Class: Nanoc::Core::DependencyProps Private

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/core/dependency_props.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

C_RAW_CONTENT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

TODO: Split raw_content for documents and collections

C::Or[
  C::SetOf[C::Or[String, Regexp]],
  C::ArrayOf[C::Or[String, Regexp]],
  C::Bool
]
C_ATTR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

C::Or[
          C::SetOf[
C::Or[
  Symbol,          # any value
  [Symbol, C::Any] # pair (specific value)
],
          ],
          C::ArrayOf[
C::Or[
  Symbol,          # any value
  [Symbol, C::Any] # pair (specific value)
]
C_ARGS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

C::KeywordArgs[
raw_content: C::Optional[C_RAW_CONTENT],
attributes: C::Optional[C_ATTR],
compiled_content: C::Optional[C::Bool]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

#initialize(raw_content: false, attributes: false, compiled_content: false, path: false) ⇒ DependencyProps

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of DependencyProps.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/nanoc/core/dependency_props.rb', line 46

def initialize(raw_content: false, attributes: false, compiled_content: false, path: false)
  @compiled_content = compiled_content
  @path = path

  @attributes =
    case attributes
    when Set
      attributes
    when Array
      Set.new(attributes)
    else
      attributes
    end

  @raw_content =
    case raw_content
    when Set
      raw_content
    when Array
      Set.new(raw_content)
    else
      raw_content
    end
end

Instance Attribute Details

#attributesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/nanoc/core/dependency_props.rb', line 9

def attributes
  @attributes
end

#raw_contentObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/nanoc/core/dependency_props.rb', line 10

def raw_content
  @raw_content
end

Instance Method Details

#activeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



177
178
179
180
181
182
183
184
# File 'lib/nanoc/core/dependency_props.rb', line 177

def active
  Set.new.tap do |pr|
    pr << :raw_content if raw_content?
    pr << :attributes if attributes?
    pr << :compiled_content if compiled_content?
    pr << :path if path?
  end
end

#attribute_keysObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



186
187
188
189
190
191
192
193
# File 'lib/nanoc/core/dependency_props.rb', line 186

def attribute_keys
  case @attributes
  when Enumerable
    @attributes.map { |a| a.is_a?(Array) ? a.first : a }
  else
    []
  end
end

#attributes?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


121
122
123
124
125
126
127
128
# File 'lib/nanoc/core/dependency_props.rb', line 121

def attributes?
  case @attributes
  when Set
    !@attributes.empty?
  else
    @attributes
  end
end

#compiled_content?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


131
132
133
# File 'lib/nanoc/core/dependency_props.rb', line 131

def compiled_content?
  @compiled_content
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/nanoc/core/dependency_props.rb', line 72

def inspect
  (+'').tap do |s|
    s << 'Props('
    s << (raw_content? ? 'r' : '_')
    s << (attributes? ? 'a' : '_')
    s << (compiled_content? ? 'c' : '_')
    s << (path? ? 'p' : '_')

    if @raw_content.is_a?(Set)
      @raw_content.each do |elem|
        s << '; raw_content('
        s << elem.inspect
        s << ')'
      end
    end

    if @attributes.is_a?(Set)
      @attributes.each do |elem|
        s << '; attr('
        s << elem.inspect
        s << ')'
      end
    end

    s << ')'
  end
end

#merge(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



141
142
143
144
145
146
147
148
# File 'lib/nanoc/core/dependency_props.rb', line 141

def merge(other)
  DependencyProps.new(
    raw_content: merge_raw_content(other),
    attributes: merge_attributes(other),
    compiled_content: compiled_content? || other.compiled_content?,
    path: path? || other.path?,
  )
end

#merge_attributes(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



154
155
156
# File 'lib/nanoc/core/dependency_props.rb', line 154

def merge_attributes(other)
  merge_prop(attributes, other.attributes)
end

#merge_prop(own, other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/nanoc/core/dependency_props.rb', line 158

def merge_prop(own, other)
  case own
  when true
    true
  when false
    other
  else
    case other
    when true
      true
    when false
      own
    else
      own + other
    end
  end
end

#merge_raw_content(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



150
151
152
# File 'lib/nanoc/core/dependency_props.rb', line 150

def merge_raw_content(other)
  merge_prop(raw_content, other.raw_content)
end

#path?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


136
137
138
# File 'lib/nanoc/core/dependency_props.rb', line 136

def path?
  @path
end

#raw_content?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


111
112
113
114
115
116
117
118
# File 'lib/nanoc/core/dependency_props.rb', line 111

def raw_content?
  case @raw_content
  when Set
    !@raw_content.empty?
  else
    @raw_content
  end
end

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



196
197
198
199
200
201
202
203
# File 'lib/nanoc/core/dependency_props.rb', line 196

def to_h
  {
    raw_content:,
    attributes:,
    compiled_content: compiled_content?,
    path: path?,
  }
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
104
105
106
107
108
# File 'lib/nanoc/core/dependency_props.rb', line 101

def to_s
  (+'').tap do |s|
    s << (raw_content? ? 'r' : '_')
    s << (attributes? ? 'a' : '_')
    s << (compiled_content? ? 'c' : '_')
    s << (path? ? 'p' : '_')
  end
end